<?php
/**
 * Result Block of ressource search
 */
use Fox\Grid\FieldCat\Field\Renderer\Anchor;
use Fox\Dao\SqlFragment;
use Hive\Contact\Status;
use Fox\Generator;

$xview = Xview::instance();

$status = array();
foreach (\Hive\Contact\Status::loadActives() as $item) {
	$status[$item->status] = $item->label();
}

$grid = new Fox\Grid("gRessource",null);
$grid->fieldcat(array("last_name","first_name","email","phone1","experience","kn_number_year","salary",array("res_status","status"),"dummy"));
$grid->fieldcat()->field("experience")->width("120");
$grid->fieldcat()->field("kn_number_year")->align("center");
$grid->fieldcat()->field("salary")->align("center");
$grid->setFieldAttr(array("last_name","first_name","experience","email","phone1"),"renderers",
					new Anchor(Fox\Generator::url("ressource","main",null,
									array("rid" => Fox\Generator::useAttribute("ressource_id"))),true));
$grid->fieldcat()->switchToObjectMode();
$grid->setCoche();
$grid->fieldcat()->setGenerators(array(
	'salary' => Fox\Generator::useFunction(function ($data,$key){
		return $data->currentPosition()->fullSalary();
	}),
	'dummy' => Fox\Generator::useFunction(function ($data,$key){
		$country = $data->address()->country;
		if(empty($country) || $country == 'fr')
		{
			$postal_code = substr($data->address()->postal_code,0,2);
			$adress = $data->address()->city;
			$adress .= empty($postal_code) ? null : ' ('.$postal_code.')';
		}
		else
		{
			$adress = \Fox\Ddic\DataElement\Text::label('country',$data->address()->country);
		}
		return $adress;

	}),
	'status' => Fox\Generator::useFunction(function ($data,$key) use($status){
		if(isset($status[$data->status])){
			return $status[$data->status];
		}
		return null;
	}),
	'experience' => Fox\Generator::useFunction(function ($data,$key){
		return "<b>{$data->currentPosition()->jobtitle}</b> chez {$data->currentPosition()->companyName}";
	}),
	'coche' => Fox\Generator::useValue('')
));
$grid->fieldcat()->behaviors(Fox\Behaviors::key(Fox\Generator::useAttribute("ressource_id")));

$grid->fieldcat()->field("dummy")->noOutput();
return $grid;